Form_SchoolMapLocPicManagement = function(){
	var obj = this;
	var storeSchool = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({url : "/map/getSchools"}),
		reader : new Ext.data.ArrayReader({fields : ["id", "name"]})
	});
	var comboSchool = new Ext.form.ComboBox({
		fieldLabel : "学校",
		name : "school",
		emptyText : "请选择学校...",
		valueField : "id",
		displayField : "name",
		editable : false,
		triggerAction : "all",
		store : storeSchool
	});
	var storeSchoolMapProxy = new Ext.data.HttpProxy({url : "/map/getSchoolMapsGoogleBySchoolId"});
	var storeSchoolMap = new Ext.data.Store({
		proxy : storeSchoolMapProxy,
		reader : new Ext.data.ArrayReader({fields : ["id", "name", "zoom", "posX", "posY"]})
	});
	var comboSchoolMap = new Ext.form.ComboBox({
		fieldLabel : "学校地图",
		name : "schoolMap",
		emptyText : "请选择学校地图...",
		valueField : "id",
		displayField : "name",
		editable : false,
		triggerAction : "all",
		store : storeSchoolMap
	});
	var storeSchoolMapLocProxy = new Ext.data.HttpProxy({url : "/map/getSchoolMapLocByGoogleMapId"});
	var storeSchoolMapLoc = new Ext.data.Store({
		proxy : storeSchoolMapLocProxy,
		reader : new Ext.data.ArrayReader({fields : ["id", "name", "zoom", "posX", "posY"]})
	});
	var comboSchoolMapLoc = new Ext.form.ComboBox({
		fieldLabel : "地点",
		name : "id",
		emptyText : "请选择地点...",
		hiddenName : "id",
		valueField : "id",
		displayField : "name",
		editable : false,
		triggerAction : "all",
		store : storeSchoolMapLoc
	});
	var storeSchoolMapLocPicProxy = new Ext.data.HttpProxy({url : "/map/getSchoolMapLocPicsByLocId"});
	var storeSchoolMapLocPic = new Ext.data.Store({
		proxy : storeSchoolMapLocPicProxy,
		reader : new Ext.data.ArrayReader({fields : ["id", "picCode", "createTime", "largePic", "smallPic"]})
	});
	function picRend(val){
		return "<img width=100 src='" + val + "'></img>";
	}
	var smSchoolMapLocPic = new Ext.grid.CheckboxSelectionModel({
		listeners: {
			selectionchange: function(sm){
				if (sm.getCount()) listSchoolMapLocPic.removeButton.enable();
				else listSchoolMapLocPic.removeButton.disable();
			}
		}
	});
	var listSchoolMapLocPic = new Ext.grid.GridPanel({
		store : storeSchoolMapLocPic,
		height : 250,
		columns : [
			{id : "pic", header : "图片", dataIndex : "smallPic", renderer : picRend, width : 110},
			{id : "id", header : "ID", dataIndex : "id", width : 50},
			{id : "picCode", header : "图片编号", dataIndex : "picCode", width : 100},
			{id : "createTime", header : "创建时间", dataIndex : "createTime", width : 80},
			{id : "smallPic", header : "小图路径", dataIndex : "smallPic", width : 220},
			{id : "largePic", header : "大图路径", dataIndex : "largePic", width : 220}
		],
		tbar : [{
			text : "删除选中图片",
			iconCls : "remove",
			ref : "../removeButton",
			disabled : true,
			listeners : {
				click : function(){
					Ext.Msg.show({
						title : "确认",
						msg : "确认删除此图片（PicCode：" + smSchoolMapLocPic.getSelected().data.picCode + "）？",
						buttons : Ext.MessageBox.YESNO,
						fn : function(button, text, opt){
							if (button == "yes"){
								Ext.Ajax.request({
									url: "/manage/removeSchoolMapLocPic",
									params : {id : smSchoolMapLocPic.getSelected().data.id},
									method : "GET",
									success: function(response, options){
										var data = Ext.util.JSON.decode(response.responseText);
										if (data == "success"){
											Ext.Msg.alert("提示", "删除成功！");
											storeSchoolMapLocPic.load();
										}  else {
											Ext.Msg.alert("错误", "错误：" + data + "。");
										}  
									},
									failure : function(){
										Ext.Msg.alert("错误", "无法连接到服务器。");
									}
								});
							}
						}
					});
				}
			}
		}],
		sm : smSchoolMapLocPic
	})
	
	storeSchoolMapProxy.addListener("beforeload", function(proxy, params){
		proxy.setUrl("/map/getSchoolMapsGoogleBySchoolId?id=" + comboSchool.getValue());
	});
	storeSchoolMapLocProxy.addListener("beforeload", function(proxy, params){
		proxy.setUrl("/map/getSchoolMapLocByGoogleMapId?id=" + comboSchoolMap.getValue());
	});
	storeSchoolMapLocPicProxy.addListener("beforeload", function(proxy, params){
		proxy.setUrl("/map/getSchoolMapLocPicsByLocId?id=" + comboSchoolMapLoc.getValue());
	});
	comboSchool.addListener("select", function(combo, record, index){
		storeSchoolMap.removeAll();
		comboSchoolMap.setValue("");
		storeSchoolMapLoc.removeAll();
		comboSchoolMapLoc.setValue("");
		storeSchoolMap.load();
	});
	comboSchoolMap.addListener("select", function(combo, record, index){
		storeSchoolMapLoc.removeAll();
		comboSchoolMapLoc.setValue("");
		storeSchoolMapLoc.load();
	});
	comboSchoolMapLoc.addListener("select", function(combo, record, index){
		storeSchoolMapLocPic.load();
	});
	
	var inputSmallPic = new Ext.form.TextField({
		fieldLabel : "小图",
		xtype : "textfield",
		name : "smallpic",
		inputType : "file",
		allowBlank : false
	});
	var inputLargePic = new Ext.form.TextField({
		fieldLabel: "大图",
		xtype : "textfield",
		name : "largepic",
		inputType : "file",
		allowBlank : false
	});
	var fieldSetMapLoc = new Ext.form.FieldSet({
		layout : "toolbar",
		items : [comboSchool, {xtype: "tbspacer", width: 10}, comboSchoolMap, {xtype: "tbspacer", width: 10}, comboSchoolMapLoc]
	});
	var fieldSetAddPic = new Ext.form.FieldSet({
		title : "添加图片",
		items : [inputSmallPic, inputLargePic]
	});
	
	Form_UserInserting.superclass.constructor.call(this, {
		fileUpload: true,
		bodyStyle: "padding: 5px",
		items : [fieldSetMapLoc, listSchoolMapLocPic, {xtype: "tbspacer", height: 10}, fieldSetAddPic],
		buttons : [{
			text : "上传",
			handler : function(){
				if (obj.getForm().isValid()){
					obj.getForm().submit({
						url : "/manage/addSchoolMapLocPic",
						waitMsg : "上传中 ...",
						success : function(form, response){
							var data = Ext.util.JSON.decode(response.response.responseText);
							Ext.Msg.alert("上传成功", data.msg);
							storeSchoolMapLocPic.load();
						},
						failure : function(form, response){
							var data = Ext.util.JSON.decode(response.response.responseText);
							Ext.Msg.alert("上传失败", data.msg);
						}
					});
				}
			}
		}]
    });
}


Ext.extend(Form_SchoolMapLocPicManagement, Ext.form.FormPanel, {
});

Ext.reg("App.MapManagement.SchoolMapLocPicManagement", Form_SchoolMapLocPicManagement);
